package com.company.project.wechat.miniProgram.controller;

import com.company.project.common.aop.annotation.LogAnnotation;
import com.company.project.common.utils.DataResult;
import com.company.project.wechat.miniProgram.entity.MiniUser;
import com.company.project.wechat.miniProgram.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author ZYF
 * @date 2021/9/13 16:34
 */
@Api(tags = "微信小程序登录接口相关")
@RestController
@RequestMapping("/wxApi")
public class LoginController {


    @Autowired
    LoginService loginService;

    @PostMapping(value = "/login")
    @ApiOperation(value = "微信小程序登录")
    @LogAnnotation(title = "微信小程序登录", action = "微信小程序登录")
    public DataResult login(@RequestBody MiniUser miniUser){
        HashMap<String,Object> map = loginService.login(miniUser.getJsCode(),miniUser.getOldJsCode(),miniUser.getEncryptedData(),miniUser.getIv());
        if((Boolean) map.get("boole")){
            return DataResult.success();
        }else{
            return DataResult.fail("操作失败，请联系管理员");
        }
    }
}
